embed tweetの展開
code:expand.js
scrapbox.PopupMenu.addButton({
title : 'Embed Tweet',
onClick : text => {
const convertContent = content => {
const replaced = content
.replace(/<a href="(https?:.*?)">(.*?)<\/a>/g, '$1 $2') .replace(/<br>/g, '\n>');
const elem = document.createElement('div');
elem.innerHTML = replaced;
return elem.innerText;
}
const tweetRegex = /<blockquote\w"\-= *><p\w"\-= *>(?<content>.*)<\/p>—(?<author>.*)(?<link><a.*>)<\/blockquote>.*<script.*?><\/script>/; const match = text.match(tweetRegex);
if(!match){
console.log('unmatch!');
return;
}
const {content, author, link} = match.groups;
return text.replace(tweetRegex, >${convertContent(content)}\n>\t—${author} ${convertContent(link)});
}
})
import '/api/code/rebuild-kitashirakawa/embed_tweetの展開/expand.js'